package com.openbravo.data.loader.serialize;

import java.math.BigDecimal;
import java.sql.Blob;
import java.sql.Clob;
import java.util.Date;

import com.openbravo.data.basic.BasicException;

public class DataReadWare implements DataRead {

    DataRead dataRead;
    int key;
    int start;

    @Override
    public Integer getInt(int columnIndex) throws BasicException {

        int realColumnIndex = columnIndex;
        if (columnIndex >= key)
            realColumnIndex += start;
        return dataRead.getInt(realColumnIndex);
    }

    @Override
    public Integer getInteger(int columnIndex) throws BasicException {
        return getInt(columnIndex);
    }


    @Override
    public String getString(int columnIndex) throws BasicException {
        int realColumnIndex = columnIndex;
        if (columnIndex >= key)
            realColumnIndex += start;
        return dataRead.getString(realColumnIndex);
    }

    @Override
    public Double getDouble(int columnIndex) throws BasicException {
        int realColumnIndex = columnIndex;
        if (columnIndex >= key)
            realColumnIndex += start;
        return dataRead.getDouble(realColumnIndex);
    }

    @Override
    public Boolean getBoolean(int columnIndex) throws BasicException {
        int realColumnIndex = columnIndex;
        if (columnIndex >= key)
            realColumnIndex += start;
        return dataRead.getBoolean(realColumnIndex);
    }

    @Override
    public Date getTimestamp(int columnIndex) throws BasicException {
        int realColumnIndex = columnIndex;
        if (columnIndex >= key)
            realColumnIndex += start;
        return dataRead.getTimestamp(realColumnIndex);
    }

    @Override
    public byte[] getBytes(int columnIndex) throws BasicException {
        int realColumnIndex = columnIndex;
        if (columnIndex >= key)
            realColumnIndex += start;
        return dataRead.getBytes(realColumnIndex);
    }

    @Override
    public Object getObject(int columnIndex) throws BasicException {
        int realColumnIndex = columnIndex;
        if (columnIndex >= key)
            realColumnIndex += start;
        return dataRead.getObject(realColumnIndex);
    }

    @Override
    public DataField[] getDataField() throws BasicException {
        int x = dataRead.getDataField().length - start + key;
        DataField[] superDataField = dataRead.getDataField();
        DataField[] dataField = new DataField[x];
        for (int i = 0; i < x; i++)
            if (i >= key)
                dataField[i] = superDataField[i + start];
            else
                dataField[i] = superDataField[i];
        return dataField;
    }

    @Override
    public long getLong(int columnIndex) throws BasicException {
        int realColumnIndex = columnIndex;
        if (columnIndex >= key)
            realColumnIndex += start;
        return dataRead.getLong(realColumnIndex);
    }

    @Override
    public Short getShort(int columnIndex) throws BasicException {
        int realColumnIndex = columnIndex;
        if (columnIndex >= key)
            realColumnIndex += start;
        return dataRead.getShort(realColumnIndex);
    }

    @Override
    public Float getFloat(int columnIndex) throws BasicException {
        int realColumnIndex = columnIndex;
        if (columnIndex >= key)
            realColumnIndex += start;
        return dataRead.getFloat(realColumnIndex);
    }

    @Override
    public BigDecimal getBigDecimal(int columnIndex) throws BasicException {
        int realColumnIndex = columnIndex;
        if (columnIndex >= key)
            realColumnIndex += start;
        return dataRead.getBigDecimal(realColumnIndex);
    }

    @Override
    public Clob getClob(int columnIndex) throws BasicException {
        int realColumnIndex = columnIndex;
        if (columnIndex >= key)
            realColumnIndex += start;
        return dataRead.getClob(realColumnIndex);
    }

    @Override
    public Blob getBlob(int columnIndex) throws BasicException {
        int realColumnIndex = columnIndex;
        if (columnIndex >= key)
            realColumnIndex += start;
        return dataRead.getBlob(realColumnIndex);
    }
}
